﻿using System;
using wojilu.Apps.Qycms.Domain;
using wojilu.Members.Users.Domain;
using wojilu.Web.Mvc;
using YBBYunQi;

namespace wojilu.Web.Controller
{
    public class UrlLinkHelp
    {
        /// <summary>
        /// 获取静态页路径
        /// </summary>
        /// <param name="lng"></param>
        /// <returns></returns>
        protected static string GetDir(String lng)
        {
            return strUtil.Join(sys.Path.Root + YBBCommon.GetConfigStr("file_htmldir"), lng + "/");
        }

        public static String GetMemberLoginLink(String Lngs)
        {
            return strUtil.Join(strUtil.Join(sys.Path.Root, "Member"), "Login") + MvcConfig.Instance.UrlExt;
        }

        public static String GetMemberRegLink(String Lngs)
        {
            return strUtil.Join(strUtil.Join(sys.Path.Root, "Member"), "Register") + MvcConfig.Instance.UrlExt;
        }

        /// <summary>
        /// 留言链接
        /// </summary>
        /// <param name="btid"></param>
        /// <param name="DLngs"></param>
        /// <param name="Lngs"></param>
        /// <returns></returns>
        public static String GetForumLink(Object btid, String DLngs, String Lngs)
        {
            var cachekey = YBBCommon.cachemenukey + "/GetForumLink/" + DLngs + Lngs;
            YBBCache cacheService = YBBCache.GetCacheService();
            object obj2 = cacheService.RetrieveObject(cachekey);
            if (obj2 == null)
            {
                if (DLngs == Lngs)
                {
                    obj2 = strUtil.Join(strUtil.Join(strUtil.Join(sys.Path.Root, "Message"), "List"), btid.ToString()) + MvcConfig.Instance.UrlExt;
                }
                else
                {
                    obj2 = strUtil.Join(strUtil.Join(strUtil.Join(strUtil.Join(sys.Path.Root, Lngs), "Message"), "List"), btid.ToString()) + MvcConfig.Instance.UrlExt;
                }
                cacheService.AddObject(cachekey, obj2, 0);
            }
            return obj2.ToString();
        }

        /// <summary>
        /// 留言提交
        /// </summary>
        /// <returns></returns>
        public static String GetForumSave(String DLngs, String Lngs)
        {
            var cachekey = YBBCommon.cachemenukey + "/GetForumSave/" + DLngs + Lngs;
            YBBCache cacheService = YBBCache.GetCacheService();
            object obj2 = cacheService.RetrieveObject(cachekey);
            if (obj2 == null)
            {
                if (DLngs == Lngs)
                {
                    obj2 = strUtil.Join(strUtil.Join(sys.Path.Root, "Public"), "MessageSave") + MvcConfig.Instance.UrlExt;
                }
                else
                {
                    obj2 = strUtil.Join(strUtil.Join(strUtil.Join(sys.Path.Root, Lngs), "Public"), "MessageSave") + MvcConfig.Instance.UrlExt;
                }
                cacheService.AddObject(cachekey, obj2, 0);
            }
            return obj2.ToString();
        }

        /// <summary>
        /// 获取内容链接
        /// </summary>
        /// <param name="Lngs"></param>
        /// <param name="did"></param>
        /// <returns></returns>
        public static String GetArticleReadLink(String DLngs, String Lngs, Object did)
        {
            var cachekey = YBBCommon.cachemenukey + "/GetArticleReadLink/" + DLngs + Lngs + did;
            YBBCache cacheService = YBBCache.GetCacheService();
            object obj2 = cacheService.RetrieveObject(cachekey);
            if (obj2 == null)
            {
                if (ConfigUtil.GetConfigInt("is_html") == 1)
                {
                    var d = Document.findById(did.ObjectToInt());
                    if (d == null)
                    {
                        return String.Empty;
                    }
                    String htmlPath = String.Empty;
                    htmlPath = strUtil.Join(GetDir(Lngs), d.filepath + "/");
                    obj2 = htmlPath + d.filename + "." + YBBCommon.GetConfigStr("file_fileex");
                }
                else
                {
                    if (DLngs == Lngs)
                    {
                        obj2 = strUtil.Join(strUtil.Join(strUtil.Join(sys.Path.Root, "Article"), "Read"), did.ToString()) + MvcConfig.Instance.UrlExt;
                    }
                    else
                    {
                        obj2 = strUtil.Join(strUtil.Join(strUtil.Join(strUtil.Join(sys.Path.Root, Lngs), "Article"), "Read"), did.ToString()) + MvcConfig.Instance.UrlExt;
                    }
                }
                cacheService.AddObject(cachekey, obj2, 0);
            }
            return obj2.ToString();
        }

        /// <summary>
        /// 获取分类链接
        /// </summary>
        /// <param name="DLngs"></param>
        /// <param name="Lngs"></param>
        /// <param name="did"></param>
        /// <returns></returns>
        public static String GetArticleLink(String DLngs, String Lngs, Object tid)
        {
            var cachekey = YBBCommon.cachemenukey + "/GetArticleLink/" + DLngs + Lngs + tid;
            YBBCache cacheService = YBBCache.GetCacheService();
            object obj2 = cacheService.RetrieveObject(cachekey);
            if (obj2 == null)
            {
                if (ConfigUtil.GetConfigInt("is_html") == 1)
                {
                    var t = TypeList.findById(tid.ObjectToInt());
                    if (t == null)
                    {
                        return String.Empty;
                    }
                    String htmlPath = String.Empty;
                    if (t.dirpath.StrIsNullOrEmpty())
                    {
                        htmlPath = strUtil.Join(GetDir(Lngs), t.dirname) + "/";
                    }
                    else
                    {
                        htmlPath = strUtil.Join(GetDir(Lngs), t.dirpath) + "/" + t.dirname + "/";
                    }
                    obj2 = htmlPath + YBBCommon.GetConfigStr("entrance_file") + "." + YBBCommon.GetConfigStr("file_fileex");
                }
                else
                {
                    if (DLngs == Lngs)
                    {
                        obj2 = strUtil.Join(strUtil.Join(strUtil.Join(sys.Path.Root, "Article"), "List"), tid.ToString()) + MvcConfig.Instance.UrlExt;
                    }
                    else
                    {
                        obj2 = strUtil.Join(strUtil.Join(strUtil.Join(strUtil.Join(sys.Path.Root, Lngs), "Article"), "List"), tid.ToString()) + MvcConfig.Instance.UrlExt;
                    }
                }
                cacheService.AddObject(cachekey, obj2, 0);
            }
            return obj2.ToString();
        }

        /// <summary>
        /// 首页链接
        /// </summary>
        /// <param name="DLngs"></param>
        /// <param name="Lngs"></param>
        /// <returns></returns>
        public static String GetHomeLink(String DLngs, String Lngs)
        {
            var cachekey = YBBCommon.cachemenukey + "/GetHomeLink/" + DLngs + Lngs;
            YBBCache cacheService = YBBCache.GetCacheService();
            object obj2 = cacheService.RetrieveObject(cachekey);
            if (obj2 == null)
            {
                var is_html = YBBCommon.GetConfigStr("is_html");
                if (DLngs == Lngs)
                {
                    obj2 = sys.Path.Root;
                    if (is_html == "1")
                    {
                        obj2 += "Index.html";
                    }
                }
                else
                {
                    if (is_html == "1")
                    {
                        obj2 += strUtil.Join(sys.Path.Root, "html/" + Lngs + "/Index.html"); 
                    }
                    else
                    {
                        obj2 = strUtil.Join(sys.Path.Root, Lngs + "/");
                    }
                }
                cacheService.AddObject(cachekey, obj2, 0);
            }
            return obj2.ToString();
        }

        public static String GetMemberCenterLink(String Lngs)
        {
            return strUtil.Join(strUtil.Join(sys.Path.Root, "Member"), "Center") + MvcConfig.Instance.UrlExt;
        }

        public static String GetFormListLink(String Lngs, Object fgid)
        {
            return strUtil.Join(strUtil.Join(strUtil.Join(sys.Path.Root, "Form"), "Read"), fgid.ToString()) + MvcConfig.Instance.UrlExt;
        }

        public static String GetEnquryListLink(String Lngs)
        {
            return strUtil.Join(strUtil.Join(sys.Path.Root, "Enqury"), "Link") + MvcConfig.Instance.UrlExt;
        }

        public static String EnquiryMainList(String Lngs)
        {
            return strUtil.Join(strUtil.Join(sys.Path.Root, "EnquiryMain"), "List") + "?al=1";
        }

        public static String MemberMailSend(String Lngs, Object Id)
        {
            return strUtil.Join(strUtil.Join(sys.Path.Root, "Public"), "MailSend") + "?k=" + DES.Encrypt(DataSecurity.UrlEncodes(Id.ToString()), "");
        }

        public static String MemberEmailMarketing(String Lngs, User user, Object userid)
        {
            return strUtil.Join(strUtil.Join(sys.Path.Root, "Public"), "EmailMarketing") + "?key=" + DES.Encrypt(DataSecurity.UrlEncodes(userid.ToString()), "") + "&code=" + DES.Encrypt(DataSecurity.UrlEncodes(user + "|" + user.Pwd), "");
        }

    }
}